//detail.js (common)
var app = getApp();
module.exports.ipage = {
  data: {
    type:"",
    remind: "加载中",
    title: "",
    date: "", 
    author: "", 
    up: "", 
    content: "", 
    image: "",
    gif: "",
    video:""
  },

  convertHtmlToText: function(inputText){
    var returnText = "" + inputText;
    returnText = returnText.replace(/<\/?[^>]*>/g, '').replace(/[ | ]*\n/g, '\n').replace(/ /ig, '')
                  .replace(/&mdash/gi,'-').replace(/&ldquo/gi,'“').replace(/&rdquo/gi,'”');
    return returnText;
  },
  
  onLoad: function(options){
    var _this = this;
    
    if(!options.type || !options.text) {
      _this.setData({
        remind: '404'
      });
      return false;
    }

    _this.setData({
      type: options.type,
      date: options.date || "",  // 发布日期
      author: options.author || "",     // 发布作者
      up: options.up || "",    // 阅读量
      title: options.title,            //新闻标题
      content: _this.convertHtmlToText(options.text),  // 新闻内容
      image:options.image,
      gif: options.gif,
      video:options.video,
      remind: ''
    });
  },
  bindImageLoadError: function(){
    this.setData({
      remind: '404'
    });
    return false;
  }
};